// const Sequelize = require('sequelize');
const {sequelize} = require("../util/mysqlConnection");
const {DataTypes} = require("sequelize");

module.exports = sequelize.define('cors', {
  id: {
    autoIncrement: true,
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING(255),
    allowNull: true
  },
  username: {
    type: DataTypes.STRING(50),
    allowNull: true,
    unique: "username_l"
  },
  passowrd: {
    type: DataTypes.STRING(255),
    allowNull: true
  },
  online: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: "在线"
  },
  port: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: "端口"
  },
  last_request: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: "最近请求时间"
  },
  create_at: {
    type: DataTypes.DATE,
    allowNull: true,
    defaultValue: sequelize.literal('CURRENT_TIMESTAMP')
  }
}, {
  sequelize,
  tableName: 'cors',
  timestamps: false,
  indexes: [
    {
      name: "PRIMARY",
      unique: true,
      using: "BTREE",
      fields: [
        { name: "id" },
      ]
    },
    {
      name: "username_l",
      unique: true,
      using: "BTREE",
      fields: [
        { name: "username" },
      ]
    },
  ]
});
